//
//  WXSSleepStatusModel.m
//  SleepBooks
//
//  Created by 王勇 on 16/9/10.
//  Copyright © 2016年 rimi. All rights reserved.
//

#import "WXSSleepStatusModel.h"

#define kStartTimeKey @"startTime"
#define kEndTimeKey @"endTime"

@implementation WXSSleepStatusModel

//-(NSTimeInterval)statusDuration{
//    if (self.endTime == nil) {
//        self.endTime = [NSDate date];
//    }
//
//    return [self.endTime timeIntervalSinceDate:self.startTime];
//}

-(NSString *)description{
    
    return [NSString stringWithFormat:@"%@----begin time: %@,endTime: %@, status duration: %.0f",[self class], self.startTime,self.endTime,self.statusDuration];
}

-(instancetype)initWithCoder:(NSCoder *)aDecoder{
    self.startTime = [aDecoder decodeObjectForKey:kStartTimeKey];
    self.endTime = [aDecoder decodeObjectForKey:kEndTimeKey];
    
    return self;
}

-(void)encodeWithCoder:(NSCoder *)aCoder{
    [aCoder encodeObject:self.startTime forKey:kStartTimeKey];
    [aCoder encodeObject:self.endTime forKey:kEndTimeKey];
}
@end

@implementation WXSDeepSleepStatusModel

+(instancetype)startDeepSleep{
    NSDate *date = [NSDate date];
    WXSDeepSleepStatusModel *deepModel = [[self alloc]init];
    deepModel.startTime = date;
    return  deepModel;
//    [NSKeyedArchiver archiveRootObject:; toFile:<#(nonnull NSString *)#>];
//    [NSKeyedUnarchiver unarchiveObjectWithFile:<#(nonnull NSString *)#>];
    
}


-(void)endDeepSleep{
    NSDate *date = [NSDate date];
    self.endTime = date;
    self.statusDuration = [date timeIntervalSinceDate:self.startTime];
}
//-(NSTimeInterval)statusDuration{
//    
//    if (self.endTime == nil) {
//        self.endTime = [NSDate date];
//    }
//    
//    return [self.endTime timeIntervalSinceDate:self.startTime];
//}

//-(NSString *)description{
////    NSLog(@"调用了重写的description");
//    
////    [super description];
//    return [NSString stringWithFormat:@"begin time：%@,endTime：%@",self.startTime,self.endTime];
//}
@end

@implementation WXSShallowSleepStatusModel

+(instancetype)startShallowSleep{
    NSDate *date = [NSDate date];
    WXSShallowSleepStatusModel *shallowModel = [[self alloc]init];
    shallowModel.startTime = date;
    return  shallowModel;
}


-(void)endShallowSleep{
    NSDate *date = [NSDate date];
    self.endTime = date;
    self.statusDuration = [date timeIntervalSinceDate:self.startTime];
}

//-(NSTimeInterval)statusDuration{
//    
//    if (self.endTime == nil) {
//        self.endTime = [NSDate date];
//    }
//    
////    WXSLog(@"睡眠开始时间（sleepStatusModel）%@,结束时间：%@",self.startTime,self.endTime);
//    
//    return [self.endTime timeIntervalSinceDate:self.startTime];
//}

//-(NSString *)description{
//    return [NSString stringWithFormat:@"开始时间：%@,结束时间：%@",self.startTime,self.endTime];
//}
@end


@implementation WXSAwakeSleepStatusModel

+(instancetype)startAwake{
    NSDate *date = [NSDate date];
    WXSAwakeSleepStatusModel *awakeModel = [[self alloc]init];
    awakeModel.startTime = date;
    return  awakeModel;
}


-(void)endAwake{
    NSDate *date = [NSDate date];
    self.endTime = date;
    self.statusDuration = [date timeIntervalSinceDate:self.startTime];
}

//-(NSTimeInterval)statusDuration{
//    
//    if (self.endTime == nil) {
//        self.endTime = [NSDate date];
//    }
//    
////    WXSLog(@"睡眠开始时间（sleepStatusModel）%@,结束时间：%@",self.startTime,self.endTime);
//    
//    return [self.endTime timeIntervalSinceDate:self.startTime];
//}

//-(NSString *)description{
////    WXSLog(@"开始时间：%@,结束时间：%@",self.startTime,self.endTime);
//    return [NSString stringWithFormat:@"开始时间：%@,结束时间：%@",self.startTime,self.endTime];
////    return nil;
//}

@end
